package cn.fxl.system.controller;
import cn.fxl.basic.pageList.GmResult;
import cn.fxl.basic.result.AjaxResult;
import cn.fxl.system.domain.SystemDictionaryDetail;
import cn.fxl.system.query.SystemDictionaryDetailQuery;
import cn.fxl.system.service.ISystemDictionaryDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/systemdictionarydetail")
public class SystemDictionaryDetailController {
    @Autowired
    private ISystemDictionaryDetailService iSystemDictionaryDetailService;

    /**
     * 获取所有
     * @return
     */
    @GetMapping
    public List<SystemDictionaryDetail> getAll(){
        return iSystemDictionaryDetailService.getAll();
    }

    /**
     * 获取单个
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public SystemDictionaryDetail getOne(@PathVariable("id") Long id){
        return iSystemDictionaryDetailService.getOne(id);
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable("id") Long id){
        try {
            iSystemDictionaryDetailService.remove(id);
            return new AjaxResult();
        } catch (Exception e) {
            return new AjaxResult(false,"删除失败");
        }
    }

    /**
     * 新增和修改
     * @param systemDictionaryDetail
     * @return
     */
    @PutMapping
    public AjaxResult saveAndUpdate(@RequestBody SystemDictionaryDetail systemDictionaryDetail){
        try {
            if (systemDictionaryDetail.getId()==null){
                iSystemDictionaryDetailService.save(systemDictionaryDetail);
            }else {
                iSystemDictionaryDetailService.update(systemDictionaryDetail);
            }
            return new AjaxResult();
        } catch (Exception e) {
            return new AjaxResult(false,"操作失败");
        }
    }

    /**
     * 高级查询 和分页查询
     * @param systemDictionaryDetailQuery
     * @return
     */
    @PostMapping
    public GmResult<SystemDictionaryDetail> querPage(@RequestBody SystemDictionaryDetailQuery systemDictionaryDetailQuery){
        return iSystemDictionaryDetailService.Pagequery(systemDictionaryDetailQuery);
    }
    @PatchMapping
    public AjaxResult pathchdel(@RequestBody Long [] a){
        try {
            iSystemDictionaryDetailService.pathchdel(a);
            return new AjaxResult();
        } catch (Exception e) {
            return new AjaxResult(false,"删除失败");
        }
    }
    @DeleteMapping("/delete/{id}")
    public AjaxResult deleteFortypeid(@PathVariable("id") Long id){
        try {
            iSystemDictionaryDetailService.deleteFortypeid(id);
            return new AjaxResult();
        } catch (Exception e) {
            return new AjaxResult(false,"删除失败");
        }
    }
    @GetMapping("/getname/{id}")
    public List<SystemDictionaryDetail> getname(@PathVariable("id") Long id){
        return iSystemDictionaryDetailService.getname(id);
    }
}
